# -*- coding: utf8 -*-
# $Id :  $



# Copyright 2008-2010, Pascal Fautrero & JCharles
#
# This file is part of PyArchiver.
# 
# PyArchiver is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyArchiver is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyArchiver.  If not, see <http://www.gnu.org/licenses/>.



# Import packages

import sys
import os.path
import platform
import wx                        # This module uses the new wx namespace
import wx.html
import VersionInfos

path = os.path.abspath(sys.argv[0])
licenceFile = os.path.join(os.path.split(path)[0], "License")

_ = wx.GetTranslation            # Define _ or add _ to builtins in your app file

#---------------------------------------------------------------------------

class HtmlWindow(wx.html.HtmlWindow):
    def __init__(self, parent):
        wx.html.HtmlWindow.__init__(self, parent, style=wx.BORDER_THEME)

        if "gtk2" in wx.PlatformInfo:
            self.SetStandardFonts()
            
    def OnLinkClicked(self, link):
        wx.LaunchDefaultBrowser(link.GetHref())
        
#---------------------------------------------------------------------------
        
class PageCopyright(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        
        html = HtmlWindow(self)
        html.SetPage(_(copyright))
        
        #-------------------------------------------------------------------
        
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(html, 1, wx.EXPAND, 0)

        #------------

        self.SetAutoLayout(True)        
        self.SetSizer(sizer)
        sizer.Fit(self)

#---------------------------------------------------------------------------
        
class PageLicence(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        
        #-------------------------------------------------------------------
        
        fontSize = self.GetFont().GetPointSize()
        
        # wx.Font(pointSize, family, style, weight, underline, faceName)
        if wx.Platform == "__WXMAC__":   
            self.normalFont = wx.Font(fontSize,
                                      wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, "")
        
        elif wx.Platform == "__WXGTK__":
            self.normalFont = wx.Font(fontSize-1,
                                      wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, "")
        
        else:
            self.normalFont = wx.Font(fontSize+2,
                                      wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, "")
        
        self.SetFont(self.normalFont)
        
        #-------------------------------------------------------------------
       
        self.field = wx.TextCtrl(self, -1, value="", size=(100, 165),
                                 style=wx.TE_LEFT | wx.TE_MULTILINE |
                                 wx.TE_READONLY | wx.BORDER_THEME)        
        self.field.SetFont(self.normalFont)

        filename = open(os.path.join(licenceFile, "COPYING_EN"))
        text_in = filename.read()
        filename.close()
        
        hello_in = text_in.decode("utf-8", "ignore")
        self.field.SetValue(hello_in)

        #-------------------------------------------------------------------
        
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.field, 1, wx.EXPAND, 0)

        #------------

        self.SetAutoLayout(True)           
        self.SetSizer(sizer)
        sizer.Fit(self)
        
#---------------------------------------------------------------------------
        
class PageDevelopers(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        
        html = HtmlWindow(self)
        html.SetPage(_(developers))

        #-------------------------------------------------------------------
        
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(html, 1, wx.EXPAND, 0)

        #------------

        self.SetAutoLayout(True)           
        self.SetSizer(sizer)
        sizer.Fit(self)
        
#---------------------------------------------------------------------------

class PageContributors(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        
        html = HtmlWindow(self)
        html.SetPage(_(contributors))

        #-------------------------------------------------------------------

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(html, 1, wx.EXPAND, 0)

        #------------

        self.SetAutoLayout(True)           
        self.SetSizer(sizer)
        sizer.Fit(self)
        
#---------------------------------------------------------------------------
        
class PageSytemInfo(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        
        html = HtmlWindow(self)
        vers = {}
        vers["pythonVersion"] = VersionInfos.PYTHONVERSION_STRING
        vers["wxPythonVersion"] =  VersionInfos.WXPYTHONVERSION_SYS_STRING
        vers["wxWidgetsVersion"] = VersionInfos.WXWIDGETSVERSION_STRING

        vers["system"] = platform.system()

        if wx.Platform == "__WXMSW__":
            vers["systemVersion"] = platform.win32_ver()[1]
        else:
            vers["systemVersion"] = platform.version()[4:10]

        vers["architecture"] = platform.machine()
        
        if wx.Platform == "__WXMSW__":
            vers["processor"] = platform.processor()
        else:
            vers["processor"] = platform.machine()           

        vers["network"] = platform.node()        
        html.SetPage(system % vers)
        
        #-------------------------------------------------------------------
        
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(html, 1, wx.EXPAND, 0)

        #------------

        self.SetAutoLayout(True)           
        self.SetSizer(sizer)
        sizer.Fit(self)

#---------------------------------------------------------------------------

copyright = _("""<h3 style='color:#d52c00;border:1px solid black;'><strong>PyArchiver</strong></h3><i>GUI wxPython for archives CD/DVD...</i><br><br><b>&copy; Copyright 2008-2010.</b><br><br><b>Sweet home : </b><body link='#06adb7'><a href='http://code.google.com/p/wxpythonarchiver/'>Sources (SVN)</a></body><br><br>License GNU-GPL version 3.""")

developers = _("""<br><br><b>Pascal Fautrero </b><i>(connecting and managing SQL database, care of the printing and managing DVD player).</i><br><br><b>JCharles </b><i>(Graphical User Interface, Internationalization (i18n)).</i>""")

contributors = _("""<br><br>I want to thank the people who, by their different sources, have enabled the achievement of this small application...<br><br><b><i>Robin Dunn, ZetCode, Werner F. Bruhin, Ianare Sevi, the wxWidgets team and all wxPython community.</i></b>""")
contributors = contributors.decode("utf-8")

# Html text with operator %()s and dictionary
system = u"""<html><body><div align="left">
<br>
<br>
●   Network : <b>%(network)s</b>.
<br>
<p>● <b>Python</b> version : <b>%(pythonVersion)s</b>,<br>
● <b>wxPython</b> version : <b>%(wxPythonVersion)s</b>,<br>
● <b>wxWidgets</b> version : <b>%(wxWidgetsVersion)s</b>.</i></p>
<br>
<p>●  OS : <b>%(system)s</b>
<b>%(systemVersion)s.</b>
<br>
<p></div></body></html>"""


